﻿using LdtJudge.DataEngine.DataBaseStores;
using LdtJudge.DataEngine.Model.CommModel;
using System;
using System.Diagnostics;

namespace LdtDataEngin.ModuleDetail
{
    /// <summary>
    /// 执行证据与质证意见对应业务
    /// </summary>
    public class EvidenceQuestionAssemble 
    {
        /// <summary>
        /// 上下文
        /// </summary>
        private DataContext _dataContext;

        /// <summary>
        /// 模块名称
        /// </summary>
        private string _moudleName;

        public EvidenceQuestionAssemble(DataContext dataContext,string moudleName)
        {
            _dataContext = dataContext;
            _moudleName = moudleName;
        }

        public void Extrat()
        {
            // 设置模块进度
            SetModuleProcess(_moudleName, 0,_dataContext.InteractiveShow.inputParameterModel);
            // 创建计时器
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            try
            {
                EvidenceQuestion evidenceQuestion = new EvidenceQuestion(_dataContext, _moudleName);
                evidenceQuestion.Extract();
            }
            catch (Exception ex)
            {
                _dataContext.InteractiveShow.LogShow("证据与质证意见模块错误：" + ex.ToString());
            }
            SetModuleProcess(_moudleName, 100, _dataContext.InteractiveShow.inputParameterModel);
            stopwatch.Stop();
            SetModuleProcess(_moudleName + "_" + stopwatch.Elapsed.TotalMilliseconds.ToString("0"), 100, _dataContext.InteractiveShow.inputParameterModel);
        }

        /// <summary>
        /// 模块执行进度
        /// </summary>
        /// <param name="moduleName">模块名称</param>
        /// <param name="nvalue">进度值</param>
        public void SetModuleProcess(string moduleName, int nvalue, MainInputParameterModel inputParameterModel)
        {
            _dataContext.InteractiveShow.ModuleProcessShow?.Invoke(moduleName, nvalue, inputParameterModel);
        }
    }
}
